<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [formGroup]="formGroup" class="formGroup">
    <lv-form-item>
        <lv-form-label>
            {{ 'protection_restore_to_label' | i18n }}
        </lv-form-label>
        <lv-form-control>
            <lv-radio-group formControlName="restoreTo">
                <lv-group [lvGutter]="'20px'">
                    <lv-radio [lvValue]="restoreLocationType.ORIGIN" [lvDisabled]="restoreToNewLocationOnly"
                        [lv-tooltip]="restoreToNewLocationOnly?('protection_origin_restore_disabled_label'| i18n):''">
                        {{ 'common_restore_to_origin_location_label' | i18n }}
                    </lv-radio>
                    <lv-radio [lvValue]="restoreLocationType.NEW">
                        {{ 'common_restore_to_new_location_label' | i18n }}
                    </lv-radio>
                </lv-group>
            </lv-radio-group>
        </lv-form-control>
    </lv-form-item>
    <ng-container *ngIf="formGroup.value.restoreTo === restoreLocationType.ORIGIN">
        <lv-form-item>
            <lv-form-label>{{'protection_cluster_label' | i18n}}</lv-form-label>
            <lv-form-control>
                <lv-select formControlName="originCluster" [lvOptions]="originClusterOptions" lvValueKey="value"
                    lvDisabled>
                </lv-select>
            </lv-form-control>
        </lv-form-item>
        <lv-form-item>
            <lv-form-label>{{'protection_name_space_label' | i18n}}</lv-form-label>
            <lv-form-control>
                <lv-select formControlName="originNamespace" [lvOptions]="originNamespaceOptions" lvValueKey="value"
                    lvDisabled>
                </lv-select>
            </lv-form-control>
        </lv-form-item>
        <lv-form-item>
            <lv-form-label>{{'protection_statefulset_label' | i18n}}</lv-form-label>
            <lv-form-control>
                <lv-select formControlName="originStatefulset" [lvOptions]="originStatefulsetOptions" lvValueKey="value"
                    lvDisabled>
                </lv-select>
            </lv-form-control>
        </lv-form-item>
    </ng-container>
    <ng-container *ngIf="formGroup.value.restoreTo === restoreLocationType.NEW">
        <lv-form-item>
            <lv-form-label lvRequired>{{'protection_cluster_label' | i18n}}</lv-form-label>
            <lv-form-control>
                <lv-select formControlName="cluster" [lvOptions]="clusterOptions" lvValueKey="value" lvShowFilter
                    lvFilterKey="label" lvFilterMode="contains">
                </lv-select>
            </lv-form-control>
        </lv-form-item>
        <lv-form-item>
            <lv-form-label lvRequired>{{'protection_name_space_label' | i18n}}</lv-form-label>
            <lv-form-control>
                <lv-select formControlName="namespace" [lvOptions]="namespaceOptions" lvValueKey="value" lvShowFilter
                    lvFilterKey="label" lvFilterMode="contains">
                </lv-select>
            </lv-form-control>
        </lv-form-item>
        <lv-form-item>
            <lv-form-label lvRequired>{{'protection_statefulset_label' | i18n}}</lv-form-label>
            <lv-form-control>
                <lv-select formControlName="statefulset" [lvOptions]="statefulsetOptions" lvValueKey="value"
                    lvShowFilter lvFilterKey="label" lvFilterMode="contains">
                </lv-select>
            </lv-form-control>
        </lv-form-item>
    </ng-container>
    <lv-form-item>
        <lv-form-label lvRequired>{{'protection_kubernetes_pvcs_map_label' | i18n}}</lv-form-label>
        <lv-form-control>
            <lv-datatable [lvData]="pvcTableData" #lvTable [lvPaginator]="page">
                <thead>
                    <tr>
                        <th>{{'protection_kubernetes_origin_pvcs_label' | i18n}}</th>
                        <th>
                            {{'protection_kubernetes_target_pvcs_label' | i18n}}
                            <i lv-icon="aui-icon-help" class="target-pvc-help"
                                lv-tooltip="{{'protection_target_pvc_help_label' | i18n}}"></i>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <ng-container *ngFor="let item of lvTable.renderData">
                        <tr>
                            <td>
                                <span lv-overflow>{{item.name}}</span>
                            </td>
                            <td>
                                <lv-select [(ngModel)]="item.targetPvc" [lvOptions]="item.targetPvcOptions"
                                    [ngModelOptions]="{standalone: true}" lvValueKey="value"
                                    (ngModelChange)='pvcChange(item)' lvShowClear>
                                </lv-select>
                            </td>
                        </tr>
                    </ng-container>
                </tbody>
            </lv-datatable>
            <div class="aui-paginator-wrap">
                <lv-paginator #page [lvPageSize]="pageSize" lvShowPageSizeOptions="false"
                    [lvPageSizeOptions]="pageSizeOptions" [lvTotal]="pvcTableData.length" lvMode="simple">
                </lv-paginator>
            </div>
        </lv-form-control>
    </lv-form-item>
    <div class="advanced-container">
        <lv-collapse [lvType]="'simple'">
            <lv-collapse-panel lvTitle="{{'common_advanced_label' | i18n}}" [lvExpanded]="false">
                <lv-form-item>
                    <lv-form-label>
                        {{'protection_proxy_host_label' | i18n}}
                    </lv-form-label>
                    <lv-form-control>
                        <lv-select [lvOptions]="proxyOptions" formControlName="proxyHost" lvValueKey='value'
                            lvShowCheckAll lvShowFilter lvFilterKey="label" lvFilterMode="contains" lvMode="multiple">
                        </lv-select>
                    </lv-form-control>
                </lv-form-item>
                <lv-form-item>
                    <lv-form-label>
                        {{ 'protection_restore_pre_script_label' | i18n }}
                        <i lv-icon="aui-icon-help" lvTooltipTheme="light" class="configform-constraint"
                            lv-tooltip="{{'protection_recovery_advance_script2_label' | i18n }}" lvColorState="true">
                        </i>
                    </lv-form-label>
                    <lv-form-control [lvErrorTip]="scriptErrorTip">
                        <input formControlName="preScript" lv-input />
                    </lv-form-control>
                </lv-form-item>
                <lv-form-item>
                    <lv-form-label>
                        {{ 'protection_restore_post_script_label' | i18n }}
                        <i lv-icon="aui-icon-help" lvTooltipTheme="light" class="configform-constraint"
                            lv-tooltip="{{'protection_recovery_advance_script2_label' | i18n }}" lvColorState="true">
                        </i>
                    </lv-form-label>
                    <lv-form-control [lvErrorTip]="scriptErrorTip">
                        <input formControlName="postScript" lv-input />
                    </lv-form-control>
                </lv-form-item>
                <lv-form-item>
                    <lv-form-label>
                        {{ 'protection_restore_fail_script_label' | i18n }}
                        <i lv-icon="aui-icon-help" lvTooltipTheme="light" class="configform-constraint"
                            lv-tooltip="{{'protection_recovery_advance_script2_label' | i18n }}" lvColorState="true">
                        </i>
                    </lv-form-label>
                    <lv-form-control [lvErrorTip]="scriptErrorTip">
                        <input formControlName="executeScript" lv-input />
                    </lv-form-control>
                </lv-form-item>
                <lv-form-item>
                    <lv-form-label>{{'common_restore_before_copy_verify_label' | i18n}}
                        <i lv-icon="aui-icon-help"
                            lv-tooltip="{{'protect_hcs_restore_before_copy_verify_label' | i18n}}"
                            lvTooltipPosition="rightTop" lvTooltipTheme="light" class="configform-constraint"
                            lvColorState='true'></i>
                    </lv-form-label>
                    <lv-form-control>
                        <lv-switch formControlName="copyVerify"
                            [lv-tooltip]="verifyStatus === CopyDataVerifyStatus.noGenerate.value ? copyVerifyDisableLabel : ''"
                            [lvDisabled]="verifyStatus === CopyDataVerifyStatus.noGenerate.value">
                        </lv-switch>
                    </lv-form-control>
                </lv-form-item>
            </lv-collapse-panel>
        </lv-collapse>
    </div>
</lv-form>

<ng-template #warnTpl>
    <span innerHTML="{{'protection_kubernetes_restore_warn_label' | i18n}}"></span>
</ng-template>